package com.ruoyi.project.system.banpostarea.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.banpostarea.domain.BanPostarea;
import com.ruoyi.project.system.banpostarea.service.IBanPostareaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 禁止下单地区Controller
 * 
 * @author LCL
 * @date 2020-12-31
 */
@Controller
@RequestMapping("/system/banpostarea")
public class BanPostareaController extends BaseController
{
    private String prefix = "system/banpostarea";

    @Autowired
    private IBanPostareaService banPostareaService;

    @RequiresPermissions("system:banpostarea:view")
    @GetMapping()
    public String banpostarea()
    {
        return prefix + "/banpostarea";
    }

    /**
     * 查询禁止下单地区列表
     */
    @RequiresPermissions("system:banpostarea:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BanPostarea banPostarea)
    {
        startPage();
        List<BanPostarea> list = banPostareaService.selectBanPostareaList(banPostarea);
        return getDataTable(list);
    }

    /**
     * 导出禁止下单地区列表
     */
    @RequiresPermissions("system:banpostarea:export")
    @Log(title = "禁止下单地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BanPostarea banPostarea)
    {
        List<BanPostarea> list = banPostareaService.selectBanPostareaList(banPostarea);
        ExcelUtil<BanPostarea> util = new ExcelUtil<BanPostarea>(BanPostarea.class);
        return util.exportExcel(list, "banpostarea");
    }

    /**
     * 新增禁止下单地区
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存禁止下单地区
     */
    @RequiresPermissions("system:banpostarea:add")
    @Log(title = "禁止下单地区", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BanPostarea banPostarea)
    {
        return toAjax(banPostareaService.insertBanPostarea(banPostarea));
    }

    /**
     * 修改禁止下单地区
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        BanPostarea banPostarea = banPostareaService.selectBanPostareaById(id);
        mmap.put("banPostarea", banPostarea);
        return prefix + "/edit";
    }

    /**
     * 修改保存禁止下单地区
     */
    @RequiresPermissions("system:banpostarea:edit")
    @Log(title = "禁止下单地区", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BanPostarea banPostarea)
    {
        return toAjax(banPostareaService.updateBanPostarea(banPostarea));
    }

    /**
     * 删除禁止下单地区
     */
    @RequiresPermissions("system:banpostarea:remove")
    @Log(title = "禁止下单地区", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(banPostareaService.deleteBanPostareaByIds(ids));
    }
}
